package com.tyqx.hashchainbackend.service.impl;


import com.tyqx.hashchainbackend.service.SysUserRoleService;
import com.tyqx.hashchainbean.module.SysUserRole;
import com.tyqx.hashchainbean.vo.SysUserRoleSave;
import com.tyqx.hashchainbean.vo.SysUserRoleVO;
import com.tyqx.hashchaindao.mapper.SysUserRoleMapper;
import hashchainutil.common.Constants;
import hashchainutil.common.EmptyUtils;
import hashchainutil.common.Page;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service("sysUserRoleService")
public class SysUserRoleServiceImpl implements SysUserRoleService {

    @Resource
    private SysUserRoleMapper sysUserRoleMapper;

    public SysUserRole getById(Long urId)throws Exception{
        return sysUserRoleMapper.getById(urId);
    }

    public List<SysUserRole> getListByMap(Map<String,Object> param)throws Exception{
        return sysUserRoleMapper.getListByMap(param);
    }

    public Integer getCountByMap(Map<String,Object> param)throws Exception{
        return sysUserRoleMapper.getCountByMap(param);
    }

    @Override
    public Integer save(SysUserRoleSave sysUserRoleSave) throws Exception {
        return sysUserRoleMapper.save(sysUserRoleSave);
    }



    public Integer modify(SysUserRole sysUserRole)throws Exception{
        return sysUserRoleMapper.modify(sysUserRole);
    }

    public Integer removeById(Long urId)throws Exception{
        return sysUserRoleMapper.removeById(urId);
    }

    public Page<List<SysUserRole>> queryPageByMap(Map<String,Object> param, Integer pageNo, Integer pageSize)throws Exception{
        Integer total = sysUserRoleMapper.getCountByMap(param);
        pageNo = EmptyUtils.isEmpty(pageNo) ? Constants.DEFAULT_PAGE_NO : pageNo;
        pageSize = EmptyUtils.isEmpty(pageSize) ? Constants.DEFAULT_PAGE_SIZE : pageSize;
        Page page = new Page(pageNo, pageSize, total);
        param.put("beginPos", page.getBeginPos());
        param.put("pageSize", page.getPageSize());
        List<SysUserRole> sysUserRoleList = sysUserRoleMapper.getListByMap(param);
        page.setRows(sysUserRoleList);
        return page;
    }

    @Override
    public List<SysUserRoleVO> getSysRoleByUserId(Long urUserId) {
        return sysUserRoleMapper.getSysRoleByUserId(urUserId);
    }

    @Override
    public Integer removeByUrRoleId(Long urRoleId) throws Exception {
        return sysUserRoleMapper.removeByUrRoleId(urRoleId);
    }

    @Override
    public Integer removeByUrUserId(Long urUserId) throws Exception {
        return sysUserRoleMapper.removeByUrUserId(urUserId);
    }

}
